home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Commodities / JoyRide / joy_tst.c < prev    next >
C/C++ Source or Header  |  1996-09-26  |  3KB  |  115 lines

  1. /***************************************************************************
  2.  
  3.                                   joy_tst
  4.  
  5.                              by Brian Koetting
  6.  
  7. ***************************************************************************/
  8.  
  9. #include <proto/intuition.h>
  10. #include <stdio.h>
  11.  
  12. struct IntuitionBase *IntuitionBase;
  13.  
  14. /*    This is the value of the IDCMP_RAWKEY code value that means:
  15.     "This is a joystick event, brought to you courtesy of JoyRide"
  16. */
  17.  
  18. #define JOY_CODE 0x7F
  19.  
  20. /**************************************************************************/
  21.  
  22. /*    This routine shows how to determine the status of the joystick.
  23.     Note that basically all you have to do is check the presence
  24.     of each applicable bit of the qualifier UWORD.
  25.     See JoyRide.Doc for details.
  26.  
  27.     Next, I simply draw a square to indicate the direction chosen.
  28. */
  29.  
  30. void draw_joy_status(struct RastPort *rp, UWORD status)
  31. {
  32.     static UWORD old_status = 0;
  33.  
  34.     /*    By performing an Exclusive-OR with the previous status,
  35.         I get only the bits that have changed.
  36.     */
  37.     old_status ^= status;
  38.  
  39.     if(old_status & IEQUALIFIER_LEFTBUTTON) RectFill(rp,90,40,110,60);
  40.     if(old_status & IEQUALIFIER_RSHIFT) RectFill(rp,115,40,135,60);
  41.     if(old_status & IEQUALIFIER_LSHIFT) RectFill(rp,65,40,85,60);
  42.     if(old_status & IEQUALIFIER_RALT) RectFill(rp,90,65,110,85);
  43.     if(old_status & IEQUALIFIER_LALT) RectFill(rp,90,15,110,35);
  44.  
  45.     old_status = status; /* save previous status for next time. */
  46.  
  47.     return;
  48. }
  49.  
  50. /**************************************************************************/
  51.  
  52. /*    In the main function, we'll just open a simple window,
  53.     and hang around waiting for either a joystick event or
  54.     a signal that the user wants to quit (either closewindow or escape)
  55.  
  56.     Note that we do _NO_ opening of the gameport.device, or anything
  57.     else to otherwise setup the joystick port.
  58. */
  59.  
  60. void main(void)
  61. {
  62.     struct Window *wndw;
  63.     struct IntuiMessage *imsg;
  64.     struct RastPort *rp;
  65.     ULONG iclass;
  66.     UWORD icode, iqual;
  67.     BOOL go = TRUE;
  68.  
  69.     IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0);
  70.     if(wndw = OpenWindowTags(NULL,
  71.         WA_Left, 50,
  72.         WA_Top, 50,
  73.         WA_Width, 200,
  74.         WA_Height, 100,
  75.         WA_IDCMP,IDCMP_RAWKEY|IDCMP_CLOSEWINDOW,
  76.         WA_Flags,WFLG_SMART_REFRESH|WFLG_ACTIVATE|
  77.             WFLG_DRAGBAR|WFLG_CLOSEGADGET|WFLG_DEPTHGADGET,
  78.         WA_Title,"JoyRide Test",
  79.         TAG_DONE)
  80.     ) {
  81.  
  82.         rp = wndw->RPort;
  83.         SetDrMd(rp,COMPLEMENT);
  84.  
  85.         while(go) {
  86.             Wait(1<<wndw->UserPort->mp_SigBit);
  87.  
  88.             while(imsg = (struct IntuiMessage *)GetMsg(wndw->UserPort)) {
  89.                 iclass = imsg->Class;
  90.                 icode = imsg->Code;
  91.                 iqual = imsg->Qualifier;
  92.                 ReplyMsg(imsg);
  93.  
  94.                 switch(iclass) {
  95.                 case IDCMP_CLOSEWINDOW:
  96.                     go = FALSE;
  97.                     break;
  98.                 case IDCMP_RAWKEY:
  99.                     if(icode == JOY_CODE) {
  100.         /* Here it is!  A joystick event! */
  101.                         draw_joy_status(rp,iqual);
  102.                     }
  103.                     else if(icode == 0x45) go = FALSE;
  104.                     break;
  105.                 }
  106.             }
  107.         }
  108.         CloseWindow(wndw);
  109.     }
  110.     CloseLibrary((struct Library *)IntuitionBase);
  111.     return;
  112. }
  113.  
  114. /**************************************************************************/
  115.